package com.example.websocket.util.response;


import lombok.Data;

import java.io.Serializable;

/**
 * @Author: puzhengbin
 * @Date: 2020/2/5 14:38
 */
@Data
public class WebResponse<T> implements Serializable {

    private static final long serialVersionUID = 1L;
    private static final int FAIL = -1;
    private static final int OK = 0;
    private String resultMsg = "success";
    //标识码，0成功 -1失败
    private int resultCode;
    private T data;

    public WebResponse(int resultCode, T data, String resultMsg) {
        this.resultCode = resultCode;
        this.data = data;
        this.resultMsg = resultMsg;
    }

    public WebResponse(int resultCode, T data) {
        this.resultCode = resultCode;
        this.data = data;
    }

    public WebResponse(int resultCode, String resultMsg) {
        this.resultCode = resultCode;
        this.resultMsg = resultMsg;
    }


    public static <E> WebResponse<E> ok(int OK, E data, String resultMsg) {
        return new WebResponse<E>(OK, data, resultMsg);
    }

    public static <E> WebResponse<E> ok(E data, String resultMsg) {
        return new WebResponse<E>(AppConst.OK, data, resultMsg);
    }

    public static <E> WebResponse<E> ok(E data) {
        return new WebResponse<E>(AppConst.OK, data, "操作成功");
    }

    public static <E> WebResponse<E> ok(int OK, E data) {
        return new WebResponse<E>(AppConst.OK, data);
    }

    public static <E> WebResponse<E> ok(String resultMsg) {
        return new WebResponse<E>(AppConst.OK, resultMsg);
    }


    public static <E> WebResponse<E> ok() {
        return new WebResponse<E>(AppConst.OK, "ok");
    }

    public static <T> WebResponse<T> ok(int OK, String resultMsg) {
        return new WebResponse<T>(OK, resultMsg);
    }

    public static <T> WebResponse<T> fail(int FAIL, String resultMsg) {
        return new WebResponse<T>(FAIL, resultMsg);
    }

    public static <T> WebResponse<T> fail(String resultMsg) {
        return new WebResponse<T>(AppConst.FAIL, resultMsg);
    }

    public static <E> WebResponse<E> fail(int FAIL, E data, String resultMsg) {
        return new WebResponse<E>(FAIL, data, resultMsg);
    }
}
